<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link rel="stylesheet" href="/com/ztree/zTreeStyle.css"/>
<script src="/com/ztree/jquery.ztree.core.js"></script>
<script src="/com/ztree/jquery.ztree.excheck.js"></script>
<script language="JavaScript">
    var zTreeObj;

    var setting = {
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: 0
            }
        },
        callback: {
            onClick: zTreeOnClick
        },
        view: {
            showLine: true,
            showIcon: true
        }
    };


    $(document).ready(function () {
        BJUI.ajax('doajax', {
            url: '/admin/dataMap/dictionaries/findAll',
            loadingmask: true,
            okCallback: function (json) {
                if (json.length > 0) {
                    zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, json);
                }
            }
        });
    });


    function zTreeOnClick(event, treeId, treeNode) {
        $("#dataMap_ajaxsearch").val(treeNode.id);
        BJUI.ajax('ajaxsearch', {
            url: '/admin/dataMap/dictionaries/findPidAll',
            form: $.CurrentNavtab.find('#dataMap_from'),
            validate: true,
            loadingmask: true,
            alertmsg: true
        })
        $("#dataMap_add_button").attr("onclick", "updataOrAddData(\'\',\'" + treeNode.id + "\');");
    }


    function menuOperation(value, data) {
        var html = '<button type="button" class="btn-green" onclick="updataOrAddData(\'' + data.id + '\',\'\');">编辑</button>'
            + '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">删除</button>';
        return html;
    }

</script>


<form id="dataMap_from" data-toggle="ajaxsearch"
      data-options="{searchDatagrid:$.CurrentNavtab.find('#dictionariesTable')}" style="display: none">
    <input id="dataMap_ajaxsearch" type="text" name="pid" class="form-control" value="0">
</form>
<div class="bjui-pageContent">
    <div style="height: 37.5%; overflow-y: auto">
        <button type="button" class="btn-gray btn-lg" onclick="javascript:BJUI.navtab('refresh')">配置
        </button>
        <button type="button" class="btn-gray btn-lg" onclick="dataMapListExport()">导出
        </button>
        <button type="button" class="btn-gray btn-lg"
                data-toggle="dialog"
                data-options="{id:'importDataMapPage', url:'/admin/dataMap/dictionaries/importDataMapPage', title:'导入'}">
            导入
        </button>
        <ul id="treeDemo" class="ztree"></ul>
    </div>
    <table id="dictionariesTable" class="table table-bordered">
    </table>
</div>

<script type="text/javascript" src="/js/toolDate.js"></script>
<script type="text/javascript">
    $(function () {
        $("#dictionariesTable").datagrid({
            height: '62.5%',
            tableWidth: '99%',
            showToolbar: true,
            filterThead: false,
            dataUrl: '/admin/dataMap/dictionaries/findPidAll',
            local: "remote",
            inlineEditMult: false,
            toolbarCustom: function () {
                return '<button id="dataMap_add_button" type="button" class="btn btn-blue" onclick="updataOrAddData(\'\',\'0\');" data-icon="plus"><i class="fa fa-plus"></i> 添加</button>';
            },
            delConfirm: true,
            afterDelete: function () {
                BJUI.navtab('refresh');
            },
            delUrl: '/admin/dataMap/dictionaries/delDictionaries',
            delPK: 'id',
            columns: [
                {
                    label: "V",
                    name: "name",
                    align: "center"
                },
                {
                    label: "K",
                    name: "key",
                    align: "center"
                },
                {
                    render: menuOperation,
                    label: '操作列'
                }
            ],
            linenumberAll: true,
            paging: {pageSize: 10, pageIndex: 1}
        });

    });

    function updataOrAddData(id, pid) {
        var updataData = "/admin/dataMap/dictionaries/updateOrAddDicView";
        var titlestr = "";
        if (id) {
            updataData = updataData + "?id=" + id;
            titlestr = "修改";
        } else {
            updataData = updataData + "?pid=" + pid;
            titlestr = "添加";
        }
        BJUI.dialog({
            id: 'updata_dataMap',
            url: updataData,
            title: titlestr,
            resizable: true,
            width: 600,
            height: 400,
            fresh: true
        });
    }

    function dataMapListExport() {
        BJUI.ajax('ajaxdownload', {
            url: '/admin/dataMap/dictionaries/excelDataMap',
        });
    }
</script>




